package com.grad.why.studentsystem.service.qlxservice.qlximpl;

import com.grad.why.studentsystem.domain.Teacher;
import com.grad.why.studentsystem.domain.current.CurrentChooseCourseInfo;
import com.grad.why.studentsystem.domain.current.CurrentCourse;
import com.grad.why.studentsystem.mapper.TeacherMapper;
import com.grad.why.studentsystem.mapper.qlxmapper.TeacherInfoMapper;
import com.grad.why.studentsystem.service.qlxservice.TeacherInfoService;
import org.python.antlr.ast.Str;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author tyh
 * @Package com.grad.why.studentsystem.service.qlxservice.qlximpl
 * @Description:
 * @date 19-5-17 上午10:56
 */
@Controller
public class TeacherInfoServiceImpl implements TeacherInfoService {


    @Autowired
    TeacherInfoMapper teacherInfoMapper;

    @Override
    public Map<String,Object> getTeacherInfo(int bindId) {
        List<Map<String,Object>> list=teacherInfoMapper.getTeacherInfo(bindId);
        if (list.size()>0){
            return list.get(0);
        }else {
            return null;
        }
    }

    @Override
    public List<CurrentChooseCourseInfo> getSelectTeacherCourseInfo(int offset, int limit,int bindId) {
        try{
            return teacherInfoMapper.getSelectTeacherCourseInfo(offset,limit,bindId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public long getSelectTeacherCourseNum(int bindId) {
        try{
            return teacherInfoMapper.getSelectTeacherCourseNum(bindId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public List<CurrentCourse> getTeacherCourseInfo(int offset, int limit, int bindId) {
        try{
            return teacherInfoMapper.getTeacherCourseInfo(offset,limit,bindId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

    @Override
    public long getTeacherCourseNum(int bindId) {
        try{
            return teacherInfoMapper.getTeacherCourseNum(bindId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return 0;
    }

    @Override
    public Map<String, Object> getTeacherCourseStudent(int courseId, int bindId) {
        long allStudentNum=this.getSelectTeacherCourseNum(bindId);
        List<CurrentChooseCourseInfo> allStudent=this.getSelectTeacherCourseInfo(0,(int)allStudentNum,bindId);
        List<String> studentName=new ArrayList<>();
        int total=0;
        for (CurrentChooseCourseInfo currentChooseCourseInfo:allStudent){
            if (currentChooseCourseInfo.getCid()==courseId){
                studentName.add(currentChooseCourseInfo.getStudentname());
                total++;
            }
        }
        Map<String,Object> courseStudentInfo=new HashMap<>();
        courseStudentInfo.put("rows",studentName);
        courseStudentInfo.put("total",total);
        return courseStudentInfo;
    }
}
